#include <iostream>
#include <string>
#include <getopt.h>

using namespace std;

struct Args {
    bool blank_ignore = false;
    bool total_only = false;
    bool recursive = false;
    bool help = false;
    string suffix;
};

void print_usage(const char* name)
{
    cout<<"\nUsage: " << name << " [options]" << std::endl
        << "Options:" << std::endl
        << "  -A, --all          print the total line number only \n"
        << "  -b,        ignore the Blank line when counting \n"
        << "  -r,        count directory Recursively \n"
        << "  -s, --suffix=FILE-SUFFIX       only count the file with specified Suffix \n"
        << "  -h, --help         display this Help and exit \n"   
        << "\n"
        << endl;
}

Args parse_args(int argc, char *argv[]) {
    option long_options[] = {
            {"all",    no_argument,       nullptr, 'A'},
            {"help",   no_argument,       nullptr, 'h'},
            {"suffix", required_argument, nullptr, 's'},
    };

    int opt, opt_idx;
    Args args;
    while ((opt = getopt_long(argc,
                              argv,
                              "Abrs:",
                              long_options,
                              &opt_idx)) != -1) {
        switch (opt) {
            case 'A':
                args.total_only = true;
                break;
            case 'b':
                args.blank_ignore = true;
                break;
            case 'r':
                args.recursive = true;
                break;
            case 's':
                args.suffix = optarg;
                break;
            case 'h':
                args.help = true;
                print_usage(argv[0]);
                break;
            default:
                break;
        }
    }
    return args;
}
